<template>
  <a-card title="今日订单销售额">
    <div :id="chartId" style="width:100%;height:380px;"></div>
  </a-card>
</template>
<script setup>
import * as echarts from 'echarts';

const props = defineProps({
  chartId:{
    type:String,
    default:"order-charts"
  }
})

const handleLoadOrderCharts = () => {
  nextTick(() => {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById(props.chartId));
    var option = option = {
      legend: {},
      tooltip: {},
      dataset: {
        dimensions: ['product', '2023', '2024'],
        source: [
          { product: '01/01', 2023: 43.3, 2024: 85.8},
          { product: '01/02', 2023: 83.1, 2024: 73.4},
          { product: '01/03', 2023: 86.4, 2024: 65.2},
          { product: '01/04', 2023: 72.4, 2024: 53.9}
        ]
      },
      xAxis: { type: 'category' },
      yAxis: {},
      // Declare several bar series, each will be mapped
      // to a column of dataset.source by default.
      series: [{ type: 'bar' }, { type: 'bar' }]
    };
    // 绘制图表
    myChart.setOption(option);
    myChart.on('click', function(params) {
      console.log("2",params);
    });

    window.addEventListener('resize', function() {
      myChart.resize();
    });


  })
}

onMounted(() => {
  handleLoadOrderCharts()
})

</script>
